package com.ruoyi.column.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.column.domain.ESub;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.column.service.IESubService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 子账号管理Controller
 *
 * @author ruoyi
 * @date 2024-11-24
 */
@RestController
@RequestMapping("/sub")
public class ESubController extends BaseController
{
    @Autowired
    private IESubService eSubService;

    /**
     * 查询子账号管理列表
     */
    @RequiresPermissions("column:sub:list")
    @GetMapping("/list")
    public TableDataInfo list(ESub eSub)
    {
        startPage();
        List<ESub> list = eSubService.selectESubList(eSub);
        return getDataTable(list);
    }

    /**
     * 导出子账号管理列表
     */
    @RequiresPermissions("column:sub:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ESub eSub)
    {
        List<ESub> list = eSubService.selectESubList(eSub);
        ExcelUtil<ESub> util = new ExcelUtil<ESub>(ESub.class);
        util.exportExcel(response, list, "子账号管理数据");
    }

    /**
     * 获取子账号管理详细信息
     */
    @RequiresPermissions("column:sub:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eSubService.selectESubById(id));
    }

    /**
     * 新增子账号管理
     */
    @RequiresPermissions("column:sub:add")
    @PostMapping
    public AjaxResult add(@RequestBody ESub eSub)
    {
        eSub.setCreateTime(new Date());
        return toAjax(eSubService.insertESub(eSub));
    }

    /**
     * 修改子账号管理
     */
    @RequiresPermissions("column:sub:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody ESub eSub)
    {
        return toAjax(eSubService.updateESub(eSub));
    }

    /**
     * 删除子账号管理
     */
    @RequiresPermissions("column:sub:remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eSubService.deleteESubByIds(ids));
    }


    @GetMapping("/updateDisable/{id}")
    public void updateDisable(@PathVariable Long id)
    {
        eSubService.updateDiable(id);
    }

    @GetMapping("/updateDisablerr/{id}")
    public void updateDisablerr(@PathVariable Long id)
    {
        eSubService.updateDiablerr(id);
    }

}
